All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sun.servlet.http.MimeHeaders

java.lang.Object
   |
   +----sun.servlet.http.MimeHeaders

public class MimeHeaders
extends Object
This class is used to contain standard internet message headers, used for SMTP (RFC822) and HTTP (RFC2068) messages as well as for MIME (RFC 2045) applications such as transferring typed data and grouping related items in multipart message bodies.

Message headers, as specified in RFC822, include a field name and a field body. Order has no semantic significance, and several fields with the same name may exist. However, most fields do not (and should not) exist more than once in a header.

Many kinds of field body must conform to a specified syntax, including the standard parenthesized comment syntax. This class supports only two simple syntaxes, for dates and integers.

When processing headers, care must be taken to handle the case of multiple same-name fields correctly. The values of such fields are only available as strings. They may be accessed by index (treating the header as an array of fields), or by name (returning an array of string values).


Constructor Index

 o MimeHeaders()
Creates a new MimeHeaders object using a default buffer size.
 o MimeHeaders(int)
Creates a new MimeHeaders object using the specified buffer size.

Method Index

 o clear()
Clears all header fields.
 o containsHeader(String)
Returns true if the specified field is contained in the header, otherwise returns false.
 o dump(PrintStream)
Dumps current headers to specified PrintStream for debugging.
 o find(String)
Finds and returns a header field with the given name.
 o getAll(byte[], int)
Get the current header fields in the byte array buf.
 o getDateHeader(String)
Returns the date value of a header with the specified name.
 o getField(int)
Returns the Nth header field, or null if there is no such header.
 o getFieldCount(String)
Returns the number of fields using a given field name.
 o getHeader(int)
Returns the body of the nth header field where n >= 0.
 o getHeader(String)
Returns the string value of one of the headers with the specified name.
 o getHeaderName(int)
Returns the name of the nth header field where n >= 0.
 o getHeaders(String)
Returns the string value of all of the headers with the specified name.
 o getIntHeader(String)
Returns the integer value of a header with the specified name.
 o names()
Returns an enumeration of strings representing the header field names.
 o putDateHeader(String)
Creates a new header field whose value is the current date and time.
 o putDateHeader(String, long)
Creates a new header field whose value is the specified time.
 o putHeader()
Adds a partially constructed field to the header.
 o putHeader(String)
Finds a header field given name.
 o putHeader(String, String)
Creates a new header field whose value is the specified string.
 o putIntHeader(String, int)
Creates a new header field whose value is the specified integer.
 o read(ServletInputStream)
Reads header fields from the specified servlet input stream until a blank line is encountered.
 o removeHeader(String)
Removes a header field with the specified name.
 o size()
Returns the current number of header fields.
 o toString()
Returns a lengthly string representation of the current header fields.
 o write(ServletOutputStream)
Writes out header fields to the specified servlet output stream.

Constructors

 o MimeHeaders
 public MimeHeaders(int len)
Creates a new MimeHeaders object using the specified buffer size.

Parameters:
len - the buffer size initially used for parsing headers
 o MimeHeaders
 public MimeHeaders()
Creates a new MimeHeaders object using a default buffer size.

Methods

 o clear
 public void clear()
Clears all header fields.

 o size
 public int size()
Returns the current number of header fields.

 o names
 public Enumeration names()
Returns an enumeration of strings representing the header field names. Field names may appear multiple times in this enumeration, indicating that multiple fields with that name exist in this header.

 o putHeader
 public void putHeader(String name,
                       String s)
Creates a new header field whose value is the specified string.

Parameters:
name - the header name
s - the header field string value
 o putIntHeader
 public void putIntHeader(String name,
                          int i)
Creates a new header field whose value is the specified integer.

Parameters:
name - the header name
i - the header field integer value
 o putDateHeader
 public void putDateHeader(String name,
                           long t)
Creates a new header field whose value is the specified time. The encoding uses RFC 822 date format, as updated by RFC 1123.

Parameters:
name - the header name
t - the time in number of milliseconds since the epoch
 o putDateHeader
 public void putDateHeader(String name)
Creates a new header field whose value is the current date and time.

Parameters:
name - the header name
 o getHeader
 public String getHeader(String name)
Returns the string value of one of the headers with the specified name.

Parameters:
name - the header field name
Returns:
the string value of the field, or null if none found
See Also:
getHeaders
 o getHeaders
 public String[] getHeaders(String name)
Returns the string value of all of the headers with the specified name.

Parameters:
name - the header field name
Returns:
array values of the fields, or null if none found
See Also:
getHeader
 o getIntHeader
 public int getIntHeader(String name) throws NumberFormatException
Returns the integer value of a header with the specified name.

Parameters:
name - the header field name
Returns:
the integer value of the header field, or -1 if the header was not found
Throws: NumberFormatException
if the integer format was invalid
 o getDateHeader
 public long getDateHeader(String name) throws IllegalArgumentException
Returns the date value of a header with the specified name.

Parameters:
name - the header field name
Returns:
the date value of the header field in number of milliseconds since the epoch, or -1 if the header was not found
Throws: IllegalArgumentException
if the date format was invalid
 o getHeaderName
 public String getHeaderName(int n)
Returns the name of the nth header field where n >= 0. Returns null if there were fewer than (n + 1) fields. This can be used to iterate through all the fields in the header.

 o getHeader
 public String getHeader(int n)
Returns the body of the nth header field where n >= 0. Returns null if there were fewer than (n + 1) fields. This can be used along with getHeaderName to iterate through all the fields in the header.

 o getField
 protected MimeHeaderField getField(int n)
Returns the Nth header field, or null if there is no such header. This may be used to iterate through all header fields.

 o getFieldCount
 public int getFieldCount(String name)
Returns the number of fields using a given field name.

 o find
 protected MimeHeaderField find(String name)
Finds and returns a header field with the given name. If no such field exists, null is returned. If more than one such field is in the header, an arbitrary one is returned.

 o removeHeader
 public void removeHeader(String name)
Removes a header field with the specified name. Does nothing if such a field could not be found.

Parameters:
name - the name of the header field to be removed
 o containsHeader
 public boolean containsHeader(String name)
Returns true if the specified field is contained in the header, otherwise returns false.

Parameters:
name - the field name
 o read
 public void read(ServletInputStream in) throws IOException
Reads header fields from the specified servlet input stream until a blank line is encountered.

Parameters:
in - the servlet input stream
Throws: IllegalArgumentException
if the header format was invalid
Throws: IOException
if an I/O error has occurred
 o write
 public void write(ServletOutputStream out) throws IOException
Writes out header fields to the specified servlet output stream.

Parameters:
out - the servlet output stream
Throws: IOException
if an I/O error has occurred
 o putHeader
 protected MimeHeaderField putHeader(String name)
Finds a header field given name. If the header doesn't exist, it will create a new one.

Parameters:
name - the header field name
Returns:
the new field
 o putHeader
 protected MimeHeaderField putHeader()
Adds a partially constructed field to the header. This field has not had its name or value initialized.

 o getAll
 public int getAll(byte buf[],
                   int buf_offset)
Get the current header fields in the byte array buf. The headers fields are placed starting at offset buf_offset.

Returns:
the number of bytes written into buf.
 o toString
 public String toString()
Returns a lengthly string representation of the current header fields.

Overrides:
toString in class Object
 o dump
 public void dump(PrintStream out)
Dumps current headers to specified PrintStream for debugging.


All Packages  Class Hierarchy  This Package  Previous  Next  Index